// Copyright (C) 2021-2021 wuchengwen. All Rights Reserved.
// Description: 线程池对外提供的头文件
// Author : wuchengwen <wuchw@foxmail.com>
// Date :2021-07-09
#include "threadpool.hpp"
#include <unistd.h>
#include <iostream>

using namespace std;

mutex coutMutex;

int main()
{
    // 创建线程池
    ThreadPool pool(3, 20);
    for (int i = 0; i < 100; ++i) {
        auto taskFunc = [i]() {
            {
                lock_guard<mutex> lock(coutMutex);
                cout << "thread " << this_thread::get_id() << "is working, number = " << i << endl;
            }
            // 目的是让线程占用较高CPU，方便查看pib
            for (int idx = 0; idx < 1000; ++idx) {
                this_thread::sleep_for(1ms);
            }
        };
        pool.AddTask(move(taskFunc));
    }
    return 0;
}